﻿@using RGA.Models
@model IEnumerable<RGA.Models.User>

@{
    ViewBag.Title = "Zarządzaj użytkownikami";
}

<h2>Użytkownicy</h2>

<p>
    @Html.ActionLink("Dodaj nowego", "Create")
</p>
<table class="table">
    <tr>
        <th>Nazwa</th>
        <th>E-mail</th>
        <th>Numer telefonu</th>
        <th>Rola</th>
        <th>Kierowcy</th>
        <th> </th>
        <th> </th>
        <th> </th>
    </tr>

    @foreach (User item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.UserName)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Email)
            </td>

            <td>
                @Html.DisplayFor(modelItem => item.PhoneNumber)
            </td>
        
            <td>
                @Html.DisplayFor(modelItem => item.Role.Name)
            </td>

        
            <td>
                @if (item.Drivers != null && item.Drivers.Count > 0)
                {
                    <ul>
                        @foreach (User m in item.Drivers)
                        {
                            <li>
                                @Html.Encode(m.UserName)
                            </li>
                        }
                    </ul>
                }
            </td>
        
            <td>
                @Html.ActionLink("Szczegóły", "Details", new {id = item.Id})
            </td>
            <td>
                @Html.ActionLink("Edytuj", "Edit", new {item.Id})
            </td>
            <td>
                @Html.ActionLink("Usuń", "Delete", new {item.Id})
            </td>
        </tr>
    }

</table>


@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}